Skip to content

DOC: Correct error message in AbstractMethodError for methodtype argument #61827

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 11, 2025

Conversation

Maaz-319
Copy link
Contributor

Fixing an error message in the AbstractMethodError class found in pandas/errors/init.py.
Currently:
raise ValueError(
f"methodtype must be one of {methodtype}, got {types} instead."
)
Here, {methodtype} and {types} are swapped.
This means if you called this error with methodtype="foo", the message would read:
methodtype must be one of foo, got {'method', 'classmethod', 'staticmethod', 'property'} instead.

That’s confusing, because the set of valid types should be listed after “must be one of”, and the invalid value you passed should be listed after “got”.

Corrected:

raise ValueError(
f"methodtype must be one of {types}, got {methodtype} instead."
)
Now, if you called this error with methodtype="foo", the message would read:
methodtype must be one of {'method', 'classmethod', 'staticmethod', 'property'}, got foo instead.

This is clearer and follows standard error message conventions.

@Maaz-319
Copy link
Contributor Author

pre-commit.ci autofix

@mroeschke mroeschke added the Error Reporting Incorrect or improved errors from pandas label Jul 11, 2025
@mroeschke mroeschke added this to the 3.0 milestone Jul 11, 2025
@mroeschke mroeschke merged commit e83b820 into pandas-dev:main Jul 11, 2025
47 checks passed
@mroeschke
Copy link
Member

Thanks @Maaz-319

@Maaz-319
Copy link
Contributor Author

Thanks @Maaz-319

Glad to contribute @mroeschke

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants